/*****************************************************************************
 *   Copyright (C) 2008 John Schember <john@nachtimwald.com>                 *
 *                                                                           *
 *   This file is part of niwwidgets.                                    *
 *                                                                           *
 *   niwwidgets is free software: you can redistribute it and/or         *
 *   modify it under the terms of the GNU General Public License as          *
 *   published by the Free Software Foundation, either version 3 of the      *
 *   License, or (at your option) any later version.                         *
 *                                                                           *
 *   niwwidgets is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of          *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the            *
 *   GNU General Public License for more details.                            *
 *                                                                           *
 *   You should have received a copy of the GNU General Public License       *
 *   along with niwwidgets. If not, see                                  *
 *   <http://www.gnu.org/licenses/>.                                         *
 *****************************************************************************/

#ifndef NIWFINDWIDGET_H
#define NIWFINDWIDGET_H

#include <QIcon>
#include <QWidget>

#include "ui_niwfindwidget.h"

/**
 * Implements a horizontal bar for finding text.
 * Put this either above or below the document.
 */
class NiwFindWidget : public QWidget, private Ui_NiwFindWidget
{
    Q_OBJECT

    public:
        NiwFindWidget(QWidget *parent=0);

        /**
            * @param FORWARD Find the next occurrence.
            * @param BACKWARD Find the previous occurrence.
            * @param CASESENSITIVE Case sensitive find.
            */
        enum NiwFindFlag {
            FORWARD,
            BACKWARD,
            CASESENSITIVE
        };
        Q_DECLARE_FLAGS(NiwFindFlags, NiwFindFlag)

        /**
         * Set the icon for the close button.
         * The close button needs an icon. No text will be shown for this
         * button. The icon is the only indication to the user of what the
         * button does.
         * @param icon The icon to be displayed on the button.
         */
        void setCloseIcon(const QIcon &icon);
        /**
         * Set the icon for the previous button.
         * @param icon The icon to be displayed on the button.
         */
        void setPreviousIcon(const QIcon &icon);
        /**
         * Set the icon for the next button.
         * @param icon The icon to be displayed on the button.
         */
        void setNextIcon(const QIcon &icon);

    signals:
        /**
         * Signals to find the specified text in the specified manner.
         * @param QString The string to find.
         * @param NiwFindFlags::FindFlags Any flags specifying how the find
         * should be preformed.
         */
        void findText(QString, NiwFindWidget::NiwFindFlags);
        /**
         * The widget should be hidden.
         */
        void wantsToClose();

    public slots:
        void setFocus();

    private slots:
        void on_closeButton_clicked();
        void on_findEdit_returnPressed();
        void on_previousButton_clicked();
        void on_nextButton_clicked();
};

#endif /* NIWFINDWIDGET_H */
